package com.haima.ziliao.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.haima.common.annotation.Log;
import com.haima.common.core.controller.BaseController;
import com.haima.common.core.domain.AjaxResult;
import com.haima.common.enums.BusinessType;
import com.haima.ziliao.domain.PDuwutype;
import com.haima.ziliao.service.IPDuwutypeService;
import com.haima.common.utils.poi.ExcelUtil;
import com.haima.common.core.page.TableDataInfo;

/**
 * 读物分类Controller
 * 
 * @author hima
 * @date 2024-11-14
 */
@RestController
@RequestMapping("/ziliao/duwutype")
public class PDuwutypeController extends BaseController
{
    @Autowired
    private IPDuwutypeService pDuwutypeService;

    /**
     * 查询读物分类列表
     */
    @PreAuthorize("@ss.hasPermi('ziliao:duwutype:list')")
    @GetMapping("/list")
    public TableDataInfo list(PDuwutype pDuwutype)
    {
        startPage();
        List<PDuwutype> list = pDuwutypeService.selectPDuwutypeList(pDuwutype);
        return getDataTable(list);
    }

    @GetMapping("/listAll")
    public AjaxResult listAll(PDuwutype pDuwutype)
    {
        List<PDuwutype> list = pDuwutypeService.selectPDuwutypeList(pDuwutype);
        return AjaxResult.success(list);
    }

    /**
     * 导出读物分类列表
     */
    @PreAuthorize("@ss.hasPermi('ziliao:duwutype:export')")
    @Log(title = "读物分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PDuwutype pDuwutype)
    {
        List<PDuwutype> list = pDuwutypeService.selectPDuwutypeList(pDuwutype);
        ExcelUtil<PDuwutype> util = new ExcelUtil<PDuwutype>(PDuwutype.class);
        util.exportExcel(response, list, "读物分类数据");
    }

    /**
     * 获取读物分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('ziliao:duwutype:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pDuwutypeService.selectPDuwutypeById(id));
    }

    /**
     * 新增读物分类
     */
    @PreAuthorize("@ss.hasPermi('ziliao:duwutype:add')")
    @Log(title = "读物分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PDuwutype pDuwutype)
    {
        return toAjax(pDuwutypeService.insertPDuwutype(pDuwutype));
    }

    /**
     * 修改读物分类
     */
    @PreAuthorize("@ss.hasPermi('ziliao:duwutype:edit')")
    @Log(title = "读物分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PDuwutype pDuwutype)
    {
        return toAjax(pDuwutypeService.updatePDuwutype(pDuwutype));
    }

    /**
     * 删除读物分类
     */
    @PreAuthorize("@ss.hasPermi('ziliao:duwutype:remove')")
    @Log(title = "读物分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pDuwutypeService.deletePDuwutypeByIds(ids));
    }
}
